package org.speed.guava;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.TimeUnit;


import org.springframework.util.Assert;

import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	
    	
    	//字符链接
    	String result = Joiner.on(",").skipNulls().join(new String[] {"a",null,"b","c","d","e"});
    	System.out.println( result);
    	String.join(",", "a","b","v");
    	
    	
    	//字符分隔
    	Iterable<String> iterable = Splitter.on(",").trimResults().omitEmptyStrings().split("this is,hello world");
    	Iterator<String> iterator = iterable.iterator();
    	while (iterator.hasNext()) {
    		System.out.println( iterator.next() );
		}
    	
    	
    	//jvm 进程内缓存
		CacheBuilder.newBuilder().expireAfterWrite(10,	TimeUnit.SECONDS).removalListener(new RemovalListener<String, Object>() {

			@Override
			public void onRemoval(RemovalNotification<String, Object> notification) {
				
				
			}
			
		}).build(new CacheLoader<String, String>(){
		
			@Override
			public String load(String key) throws Exception {
				
				return null;
			}
			
		});
    	
    	//类似于断言
		String result1 = "";
		Preconditions.checkArgument(true, "error!");
		Preconditions.checkNotNull(result1,"result1 Is Null");
		Objects.requireNonNull(result1, "result1 Is Null");
		Assert.notNull(result1, "result1 Is Null");
		
    
		//创建集合
		HashMap<String, String> map = Maps.newHashMap();
		ArrayList<String> list = Lists.newArrayList();
		
		
		ImmutableMap<String, String> aMap = ImmutableMap.of("a", "1","b","1");
		System.out.println( aMap );
		
		
        System.out.println( "Hello World!" );
    }                                                                                                                                     
}
